
function f1(x) { return x * 2 }
function f2(x) { return x + 2 }
function f3(x) { return Math.pow(x, 2) }

function chained(functions) {
    var func = function(x){
        var funcRes = functions[0](x)
        for (let i = 1; i < functions.length; i++) {
            funcRes = functions[i](funcRes)
        }
        return funcRes
    }
    return func
}

console.log(chained([f1,f2,f3])(2));


// d(c(b(a(0))))
